Passed
Pull Request — master (#223)
by Daniel
01:35
created

classFetchRemoteData.fetchRemoteData   A

Complexity

Conditions 1

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 21
rs 9.65
c 0
b 0
f 0
cc 1
1
// Class imports
2
import classShowHideElements from "./classShowHideElements";
3
import classErrorHandler from "../ErrorHandler/classErrorHandler";
4
5
/**
6
 * Class responsible for fetching the remote data
7
 */
8
const fetchRemoteData = async () => {
9
  const bilInformasjon = (<HTMLInputElement>(
10
    document.getElementById("bilinformasjon")
11
  )).value;
12
  const API_URL = "/api/getRegNummer?regNummer=";
13
  const regNummer = `${API_URL}${bilInformasjon}`;
14
  let bilResponse = "";
15
16
  try {
17
    const response = await fetch(regNummer);
18
    bilResponse = await response.text();
19
  } catch (error) {
20
    classShowHideElements.hideElements();
21
    classErrorHandler.showErrorFetchingRegNr();
22
  }
23
  return JSON.parse(bilResponse);
24
};
25
26
export default { fetchRemoteData };
27